﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Tasks;
using System.Windows.Media.Imaging;
using Microsoft.Xna.Framework.Media;
using BUS;

namespace ProjectM2Work.Pages
{
    public partial class PageThemTu : PhoneApplicationPage
    {
        public PhotoChooserTask _photoChooserTask;
        public PageThemTu()
        {
            InitializeComponent();
            _photoChooserTask = new PhotoChooserTask();
            _photoChooserTask.Completed += new EventHandler<PhotoResult>(_photoChooserTask_Completed);
        }

        void _photoChooserTask_Completed(object sender, PhotoResult e)
        {
            if (e.TaskResult == TaskResult.OK)
            {
                
                //Code to display the photo on the page in an image control named myImage.
                BitmapImage bmp = new BitmapImage();
                bmp.SetSource(e.ChosenPhoto);
                txtLinkVideo.Text = e.OriginalFileName;
                //myImage.Source = bmp;
            }
        }

        private void image4_MouseLeave(object sender, MouseEventArgs e)
        {
            App.ZoomInImage(sender);
        }

        private void image4_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            App.ZoomOutImage(sender);
        }

        private void image4_MouseMove(object sender, MouseEventArgs e)
        {
            App.ZoomOutImage(sender);
        }

        private void image4_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            NavigationService.Navigate(new Uri("/Pages/PageThongTin.xaml", UriKind.Relative));
        }

        private void image2_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            if (NavigationService.CanGoBack)
            {
                NavigationService.GoBack();
            }
        }

        private void image3_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            _photoChooserTask.Show();
        }

        
        private void image1_ImageFailed(object sender, ExceptionRoutedEventArgs e)
        {

        }

        private void imgHuy_ImageFailed(object sender, ExceptionRoutedEventArgs e)
        {
        }

        /// <summary>
        /// nhấn connect to server to add record
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void imgTaiLen_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            if (txtEmail.Text != "" && txtHoTen.Text != "" &&
                txtLinkVideo.Text != "" && txtMota.Text != "" &&
                txtTu.Text != "")
            {
                Service_m2work._clientUpLoadDTO.Hoten = txtHoTen.Text;
                Service_m2work._clientUpLoadDTO.Email = txtEmail.Text;
                Service_m2work._clientUpLoadDTO.Mota = txtMota.Text;
                Service_m2work._clientUpLoadDTO.Tu = txtTu.Text;

                Service_m2work.AddRecordUpLoad();
            }
            else
            {
                MessageBox.Show("Bạn Phải Điền Đầy Đủ Thông Tin", "Thông Báo", MessageBoxButton.OK);
            }
        }
    }
}